﻿using AutoMapper;
using ManagementApi.Models.System.Role;
using Modules.Cms;
using Modules.System.Role;
using Modules.System.User;
using PmSoft;

namespace ManagementApi.Models.Cms
{
    public class CmsOrderDto
    {
        /// <summary>
        /// 主键
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 创建人ID
        /// </summary>
        public int CreateUserId { get; set; }

        /// <summary>
        /// 创建人名称
        /// </summary>
        public string CreateUserName { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateDt { get; set; }

        /// <summary>
        /// 更新人ID
        /// </summary>
        public int UpdateUserId { get; set; }

        /// <summary>
        /// 更新人名称
        /// </summary>
        public string UpdateUserName { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdateDt { get; set; }

        /// <summary>
        /// 删除标识
        /// </summary>
        public bool IsDeleted { get; set; }
        /// <summary>
        /// 经销商id
        /// </summary>
        public int DealerId { get; set; }

        /// <summary>
        /// 单据号
        /// </summary>
        public string BillNo { get; set; }

        /// <summary>
        /// 出库时间
        /// </summary>
        public DateTime? OutboundDt { get; set; }

        /// <summary>
        /// 出库数量
        /// </summary>
        public int? OutboundQty { get; set; }

        /// <summary>
        /// 收货人
        /// </summary>
        public string Consignee { get; set; }

        /// <summary>
        /// 收获状态;10 未收货  20 已收货
        /// </summary>
        public int? ConsigneeStatus { get; set; }

        /// <summary>
        /// 收货时间
        /// </summary>
        public DateTime? ConsigneeDt { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Remark { get; set; }
        /// <summary>
        /// 类型 10 出库单  20 入库单
        /// </summary>
        public int Type { get; set; }

        #region 扩展字段
        public string DealerName { get; set; }
        #endregion
    }

    public static partial class CmsOrderExceptions
    {
        public static CmsOrderDto AsDto(this Modules.Cms.Entitys.CmsOrder entity)
        {
            var mapper = ServiceAccessor.GetService<IMapper>();
            var cmsDealerService = ServiceAccessor.GetService<CmsDealerService>();
            CmsOrderDto dto = new CmsOrderDto();
            dto.DealerName = cmsDealerService.Get(entity.DealerId)?.Name ?? "";
            mapper.Map(entity, dto);
            return dto;

        }
    }
}
